package company

import (
	"github.com/gin-gonic/gin"
	"jwgin/model/mysql"
	"jwgin/service"
)

type gift struct{}

func (l *gift) Routers(Router *gin.RouterGroup) (R gin.IRoutes) {
	//资源列表
	Router.GET("gift", l.get) //列表
	return Router
}

func (l *gift) get(c *gin.Context) {
	count, size, offset := pages(c)
	ret := []mysql.Gift{}
	//创建DB
	db := service.G.Model(&mysql.Gift{})

	//名字
	if name := c.Query("name"); name != "" {
		db = db.Where("name = ?", name)
	}

	//状态
	if statu := c.Query("statu"); statu != "" {
		db = db.Where("statu = ?", statu)
	}

	err := db.Count(&count).Offset(offset).Limit(size).Find(&ret).Error
	if err != nil {
		RespErr(c, err)
		return
	}
	RespList(c, count, ret)
}
